package com.kkb.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class GlobalExecptionHandler {
    @ExceptionHandler(UnameErrorException.class)
    public ModelAndView exHandler1(Exception ex){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",ex.getMessage());
        modelAndView.setViewName("nameError");
        return modelAndView;
    }
    @ExceptionHandler(PasswordErrorException.class)
    public ModelAndView exHandler2(Exception ex){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",ex.getMessage());
        modelAndView.setViewName("passwordError");
        return modelAndView;
    }
    @ExceptionHandler(Exception.class)
    public ModelAndView exHandler3(Exception ex){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",ex.getMessage());
        modelAndView.setViewName("error");
        return modelAndView;
    }
}
